package com.akw.boot3.core.controller;

import com.akw.boot3.core.entity.UserEntity;
import com.akw.boot3.core.event.EventPublisher;
import com.akw.boot3.core.event.LoginSuccessEvent;
import com.akw.boot3.core.service.AccountService;
import com.akw.boot3.core.service.CouponService;
import com.akw.boot3.core.service.SysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private CouponService couponService;

    @Autowired
    private SysService service;

    @Autowired
    private EventPublisher eventPublisher;

    @GetMapping("/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password) {
        // 业务处理登录

        // 1. 账户服务自动签到加积分
//        accountService.addAccountScore(username, 10);
        // 2. 优惠服务随机发放优惠券
//        couponService.sendCoupon(username);
        // 3. 系统服务等级用户登录的想信息
//        service.recordLog(username);
        LoginSuccessEvent event = new LoginSuccessEvent(new UserEntity("AKW", "123456"));
        eventPublisher.sendEvent(event);
        return username + "login success";
    }
}
